package com.niodata.dp.core.resource;

public abstract class AbstractResourceDetailResolver implements ResourceDetailResolver {

  public ResourceDetail resolve(Resource resource) {
    if (!this.supportResourceType(resource.resourceType().getClass())) {
      throw new RuntimeException("can not resolve resource type:" + resource.getClass());
    }
    String identifier = this.parseIdentifier(resource);
    return this.doResolve(resource.resourceType(), identifier);
  }

  protected String parseIdentifier(Resource resource) {
    return resource.content();
  }

  public abstract ResourceDetail doResolve(ResourceType resourceType, String identifier);

}
